<?php
class dbConfig {
	public $pconnect = 0;
	public $query_num = 0;
	public function __construct($dbhost, $dbuser, $dbpw, $dbname) {
		$this->connect($dbhost, $dbuser, $dbpw, $dbname);
	}
	
	public function connect($dbhost, $dbuser, $dbpw, $dbname) {
		$this->pconnect==0 ? @mysql_connect($dbhost, $dbuser, $dbpw) : @mysql_pconnect($dbhost, $dbuser, $dbpw);
		if (mysql_error()!=0) {
			die("Can not connect to database!");
		}
		
		if($dbname) {
			if(!@mysql_select_db($dbname)) {
				die("Can not connect to you $dbname");
			}
		}
	}
	
	public function close() {
		return mysql_close();
	}
	
	function query($SQL,$method='') {
		if($method=='U_B' && function_exists('mysql_unbuffered_query')){
			$query = mysql_unbuffered_query($SQL);
		}else{
			$query = mysql_query($SQL);
		}
		
		if (!$query)  {
			die('Query Error: ' . $SQL);
		}
		return $query;
	}
	
	function get_one($SQL){
		$query=$this->query($SQL,'U_B');		
		$rs =& mysql_fetch_array($query, MYSQL_ASSOC);
		return $rs;
	}
	
	function update($SQL) {
		if(function_exists('mysql_unbuffered_query')){
			$query = mysql_unbuffered_query($SQL);
		}else{
			$query = mysql_query($SQL);
		}
		$this->query_num++;

		if (!$query) {
			die('Update Error: ' . $SQL);
		}
		return $query;
	}
	
	function num_rows($query) {
		$rows = mysql_num_rows($query);
		return $rows;
	}
	
	function insert_id() {
		$id = mysql_insert_id();
		return $id;
	}
}
?>